package com.example.administrator.liangcang.fragment;


import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.administrator.liangcang.R;
import com.example.administrator.liangcang.store.fragment.BrandFragment;
import com.example.administrator.liangcang.store.fragment.GiftFragment;
import com.example.administrator.liangcang.store.fragment.HomeFragment;
import com.example.administrator.liangcang.store.fragment.ThemeFragment;
import com.example.administrator.liangcang.databinding.FragmentStoreBinding;
import com.example.administrator.liangcang.until.CommentPagerFragmentAdapter;

import java.util.ArrayList;
import java.util.List;


/**
 * A simple {@link Fragment} subclass.
 */
public class StoreFragment extends Fragment {
    private FragmentStoreBinding binding;
    private List<Fragment> fragments;
    private String[] title;

    public StoreFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return DataBindingUtil.inflate(inflater, R.layout.fragment_store, container, false).getRoot();
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        binding = DataBindingUtil.getBinding(view);
        aboutFragment();
        aboutTablayout();
    }

    private void aboutFragment() {
        fragments = new ArrayList<>();
        fragments.add(new ThemeFragment());
        fragments.add(new BrandFragment());
        fragments.add(new HomeFragment());
        fragments.add(new ThemeFragment());
        fragments.add(new GiftFragment());
        title = new String[]{"分类", "品牌", "首页", "专辑", "礼物"};
    }

    private void aboutTablayout() {
        CommentPagerFragmentAdapter adapter = new CommentPagerFragmentAdapter(getChildFragmentManager(), fragments, title);
        binding.pager.setAdapter(adapter);
        binding.tabLayout.setupWithViewPager(binding.pager);
        binding.pager.setCurrentItem(2);
        binding.pager.setOffscreenPageLimit(5);
    }
}
